package 对象数组;

import java.util.ArrayList;

// 需求：自定义4个学生对象，添加到集合，并且遍历
public class 自定义对象集合 {
    public static void main(String[] args) {

        student a = new student(21, "张三");
        student b = new student(22, "王二");
        student c = new student(23, "李四");
        student d = new student(24, "陈五");

        ArrayList<student> list = new ArrayList<>();
        list.add(a);
        list.add(b);
        list.add(c);
        list.add(d);

        for (int i = 0; i < list.size(); i++) {
            System.out.println("姓名：" + list.get(i).getName() + "  年龄：" + list.get(i).getAge());
        }

    }
}
